home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Views / Tiled Views / TiledView.cp < prev    next >
Text File  |  2000-06-23  |  4KB  |  170 lines

  1. // TiledView.cp
  2.  
  3. #ifndef TiledView_h
  4. #include "TiledView.h"
  5. #endif
  6. #ifndef Canvas_h
  7. #include "Canvas.h"
  8. #endif
  9. #ifndef CellVisitor_h
  10. #include "CellVisitor.h"
  11. #endif
  12. #ifndef TiledPane_h
  13. #include "TiledPane.h"
  14. #endif
  15. #ifndef MinMax_h
  16. #include "MinMax.h"
  17. #endif
  18. #ifndef ValidAndInvalidCanvasLoop_h
  19. #include "ValidAndInvalidCanvasLoop.h"
  20. #endif
  21. #ifndef CanvasScreenLoop_h
  22. #include "CanvasScreenLoop.h"
  23. #endif
  24.  
  25. void TiledView::Deliver( CellVisitor& visitor, const Canvas& canvas )
  26.   {
  27.     Canvas scratch;
  28.     Rectangle32 destination( canvas.FromScreen( visitor.Destination() ) );
  29.     
  30.     for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
  31.         pane->Deliver( visitor, canvas, scratch, destination );
  32.   }
  33.  
  34. void TiledView::ShufflePanes( TiledPane *shuffleFirst )
  35.   {
  36.     for ( TiledPane* pane = shuffleFirst;
  37.             pane != 0;
  38.             pane = pane->shuffleNext )
  39.       {
  40.         // Remember the old bounds for a moment in proposedBounds.
  41.         Rectangle32 newBounds = pane->proposedBounds;
  42.         pane->proposedBounds = pane->Bounds();
  43.         pane->SetBounds( newBounds );
  44.       }
  45.     
  46.     for ( ValidAndInvalidCanvasLoop parentCanvas( *this );
  47.             parentCanvas.Unfinished();
  48.             parentCanvas++ )
  49.         for ( CanvasScreenLoop screenCanvas( *parentCanvas );
  50.                 screenCanvas.Unfinished();
  51.                 screenCanvas++ )
  52.           {
  53.             Canvas uncopied( *screenCanvas );
  54.             
  55.             for ( TiledPane* pane = shuffleFirst;
  56.                     pane != 0;
  57.                     pane = pane->shuffleNext )
  58.               {
  59.                 Canvas oldCanvas( *screenCanvas );
  60.                 oldCanvas.Submap( pane->proposedBounds );
  61.  
  62.                 Canvas newCanvas( *screenCanvas );
  63.                 newCanvas.Submap( pane->Bounds() );
  64.                 
  65.                 Copy( oldCanvas, newCanvas );
  66.                 
  67.                 uncopied.ObstructOffScreen( pane->Bounds() );
  68.               }
  69.           }
  70.   }
  71.  
  72. void TiledView::ShufflePanesForward()
  73.   {
  74.     for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
  75.         pane->shuffleNext = ( pane->link.Next() == 0 )
  76.                                   ? 0
  77.                                   : &**pane->link.Next();
  78.     ShufflePanes( *Panes().First() );
  79.   }
  80.  
  81. void TiledView::ShufflePanesBackward()
  82.   {
  83.     for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
  84.         pane->shuffleNext = ( pane->link.Previous() == 0 )
  85.                                   ? 0
  86.                                   : &**pane->link.Previous();
  87.     ShufflePanes( *Panes().Last() );
  88.   }
  89.  
  90. int32 TiledView::MinimumOf( Measurement measurement ) const
  91.   {
  92.     int32 minimum = maxint32;
  93.  
  94.     for ( PaneLoop pane( Panes() );
  95.             minimum > 0 && pane.Unfinished();
  96.             pane++ )
  97.         minimum = Min( minimum, (pane->Sizer().*measurement)() );
  98.  
  99.     return minimum;
  100.   }
  101.  
  102. int32 TiledView::MaximumOf( Measurement measurement ) const
  103.   {
  104.     int32 maximum = 0;
  105.  
  106.     for ( PaneLoop pane( Panes() );
  107.             maximum < maxint32 && pane.Unfinished();
  108.             pane++ )
  109.         maximum = Max( maximum, (pane->Sizer().*measurement)() );
  110.  
  111.     return maximum;
  112.   }
  113.  
  114. int32 TiledView::TotalOf( Measurement measurement ) const
  115.   {
  116.     int32 total = 0;
  117.     
  118.     for ( PaneLoop pane( Panes() );
  119.             total < maxint32 && pane.Unfinished();
  120.             pane++ )
  121.         total += Min( (pane->Sizer().*measurement)(), maxint32 - total );
  122.     
  123.     return total;
  124.   }
  125.  
  126. int32 TiledView::TotalProposedSize() const
  127.   {
  128.     int32 total = 0;
  129.     for ( PaneLoop pane( Panes() ); pane.Unfinished(); pane++ )
  130.         total += pane->proposedSize;
  131.     return total;
  132.   }
  133.  
  134. void TiledView::Add( TiledPane& toAdd, BeforeStart )
  135.   {
  136.     panes.Add( toAdd.link, beforeStart );
  137.     toAdd.SetParent( this );
  138.   }
  139.  
  140. void TiledView::Add( TiledPane& toAdd, AfterEnd )
  141.   {
  142.     panes.Add( toAdd.link, afterEnd );
  143.     toAdd.SetParent( this );
  144.   }
  145.  
  146. void TiledView::Add( TiledPane& toAdd, Before, const TiledPane& position )
  147.   {
  148.     panes.Add( toAdd.link, before, position.link );
  149.     toAdd.SetParent( this );
  150.   }
  151.  
  152. void TiledView::Add( TiledPane& toAdd, After, const TiledPane& position )
  153.   {
  154.     panes.Add( toAdd.link, after, position.link );
  155.     toAdd.SetParent( this );
  156.   }
  157.  
  158. void TiledView::Remove( TiledPane& toRemove )
  159.   {
  160.     toRemove.SetParent( 0 );
  161.     panes.Remove( toRemove.link );
  162.   }
  163.  
  164. void TiledView::RemoveAll()
  165.   {
  166.     while ( !panes.IsEmpty() )
  167.         Remove( **panes.First() );
  168.   }
  169.  
  170.